package data;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;


/*
 * 读取配置文件
 * markersNum:探针位点总数
 * chromsomeNum:染色体种类数
 * genesNum:基因数目
 * posMin:最小值（实际位置）
 * posMax:最大值（实际位置）
 * samplesNum:样本数
 * passengersNum:乘客数目
 * passengersVal:乘客拷贝数值
 * passengersflag:乘客长度是否为染色体长度，true为arm，false为focal
 * driversMidPos:窗口中心点位置（第几个探针，而不是具体位置）
 * driversWidth:窗口宽度
 * driversVal:窗口高度值（拷贝数数值）
 * alpha:α（用于空间噪声）  窗口大小的乘性系数
 * beta:β （用于空间噪声）  随机移动位点中值
 * sigma:σ (用于强度噪声)  用于数据的取值
 *
 * */
public class Reader {
    private String markersNum;
    private String chromsomeNum;
    private String genesNum;
    private String posMin;
    private String posMax;
    private String samplesNum;
    private String passengersNum;
    private String passengersWidth;
    private String passengersVal;
    private String passengersFlag;
    private String[] driversMidPos;
    private String[] driversWidth;
    private String[] driversVal;
    private String alpha;
    private String beta;
    private String sigma;

    public String getMarkersNum() {
        return markersNum;
    }

    public void setMarkersNum(String markersNum) {
        this.markersNum = markersNum;
    }

    public String getChromsomeNum() {
        return chromsomeNum;
    }

    public void setChromsomeNum(String chromsomeNum) {
        this.chromsomeNum = chromsomeNum;
    }

    public String getGenesNum() {
        return genesNum;
    }

    public void setGenesNum(String genesNum) {
        this.genesNum = genesNum;
    }

    public String getPosMin() {
        return posMin;
    }

    public void setPosMin(String posMin) {
        this.posMin = posMin;
    }

    public String getPosMax() {
        return posMax;
    }

    public void setPosMax(String posMax) {
        this.posMax = posMax;
    }

    public String getSamplesNum() {
        return samplesNum;
    }

    public void setSamplesNum(String samplesNum) {
        this.samplesNum = samplesNum;
    }

    public String getPassengersNum() {
        return passengersNum;
    }

    public void setPassengersNum(String passengersNum) {
        this.passengersNum = passengersNum;
    }

    public String getPassengersWidth() {
        return passengersWidth;
    }

    public void setPassengersWidth(String passengersWidth) {
        this.passengersWidth = passengersWidth;
    }

    public String getPassengersVal() {
        return passengersVal;
    }

    public void setPassengersVal(String passengersVal) {
        this.passengersVal = passengersVal;
    }

    public String getPassengersFlag() {
        return passengersFlag;
    }

    public void setPassengersFlag(String passengersFlag) {
        this.passengersFlag = passengersFlag;
    }


    public String[] getDriversMidPos() {
        return driversMidPos;
    }

    public void setDriversMidPos(String[] driversMidPos) {
        this.driversMidPos = driversMidPos;
    }

    public String[] getDriversWidth() {
        return driversWidth;
    }

    public void setDriversWidth(String[] driversWidth) {
        this.driversWidth = driversWidth;
    }

    public String[] getDriversVal() {
        return driversVal;
    }

    public void setDriversVal(String[] driversVal) {
        this.driversVal = driversVal;
    }

    public String getAlpha() {
        return alpha;
    }

    public void setAlpha(String alpha) {
        this.alpha = alpha;
    }

    public String getBeta() {
        return beta;
    }

    public void setBeta(String beta) {
        this.beta = beta;
    }

    public String getSigma() {
        return sigma;
    }

    public void setSigma(String sigma) {
        this.sigma = sigma;
    }

    public Reader(String fileName){
        DocumentBuilderFactory domfac=DocumentBuilderFactory.newInstance();
        try {
            DocumentBuilder dombuilder=domfac.newDocumentBuilder();
            InputStream is=new FileInputStream(fileName);
            Document doc=dombuilder.parse(is);
            Element root=doc.getDocumentElement();
            NodeList parameters=root.getChildNodes();
            if(parameters!=null){
                for(int i=0;i<parameters.getLength();i++){
                    Node details=parameters.item(i);
                    for(Node node=details.getFirstChild();node!=null;node=node.getNextSibling()){
                        if(node.getNodeType()==Node.ELEMENT_NODE){
                            if(node.getNodeName().equals("markersNum")){
                                setMarkersNum(node.getFirstChild().getNodeValue());
                            }
                            if(node.getNodeName().equals("chromsomeNum")){
                                setChromsomeNum(node.getFirstChild().getNodeValue());
                            }
                            if(node.getNodeName().equals("genesNum")){
                                setGenesNum(node.getFirstChild().getNodeValue());
                            }
                            if(node.getNodeName().equals("posMin")){
                                setPosMin(node.getFirstChild().getNodeValue());
                            }
                            if(node.getNodeName().equals("posMax")){
                                setPosMax(node.getFirstChild().getNodeValue());
                            }
                            if(node.getNodeName().equals("samplesNum")){
                                setSamplesNum(node.getFirstChild().getNodeValue());
                            }
                            if(node.getNodeName().equals("passengersNum")){
                                setPassengersNum(node.getFirstChild().getNodeValue());
                            }
                            if(node.getNodeName().equals("passengersWidth")){
                                setPassengersWidth(node.getFirstChild().getNodeValue());
                            }
                            if(node.getNodeName().equals("passengersVal")){
                                setPassengersVal(node.getFirstChild().getNodeValue());
                            }
                            if(node.getNodeName().equals("passengersFlag")){
                                setPassengersFlag(node.getFirstChild().getNodeValue());
                            }
                            if(node.getNodeName().equals("driversMidPos")){
                                setDriversMidPos(node.getFirstChild().getNodeValue().split(","));
                            }
                            if(node.getNodeName().equals("driversWidth")){
                                setDriversWidth(node.getFirstChild().getNodeValue().split(","));
                            }
                            if(node.getNodeName().equals("driversVal")){
                                setDriversVal(node.getFirstChild().getNodeValue().split(","));
                            }
                            if(node.getNodeName().equals("alpha")){
                                setAlpha(node.getFirstChild().getNodeValue());
                            }
                            if(node.getNodeName().equals("beta")){
                                setBeta(node.getFirstChild().getNodeValue());
                            }
                            if(node.getNodeName().equals("sigma")){
                                setSigma(node.getFirstChild().getNodeValue());
                            }
                        }
                    }
                }
            }
        } catch (ParserConfigurationException e) {
            e.printStackTrace();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (SAXException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
